<template>
  <el-tree :props="props" :load="loadNode"  @node-click="clickHandle" accordion lazy>
  </el-tree>
</template>

<script>
export default {
  data() {
    return {
      props: {
        label: 'name',
        children: 'zones',
        isLeaf: 'leaf'
      },
      treeData: []
    };
  },
  methods: {
    loadNode(node, resolve) {
      if (node.level === 0) {
        this.$api.selectItemCategoryByParentId()
          .then(res => {
            if (res.data.status == 200) {
              // //console.log('tree类目结构', res.data.result)
              return resolve(res.data.result);
            } else {
              return resolve([]);
            }
          }
          )
      }
      if (node.level >= 1) {
        this.$api.selectItemCategoryByParentId({ type: node.data.cid })
          .then(res => {
            if (res.data.status == 200) {
              return resolve(res.data.result);
            } else {
              return resolve([]);
            }
          }
          )
      }
    },
    // 点击tree节点触发事件
    clickHandle(data,node){
      // //console.log('data,node',data,node) //node中包含父节点信息
      this.$emit('sendTreeData',data,node)
    },
  }
}
</script> 

<style scoped></style>
